﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BusinessRule.cs" company="SMART business">
//   Copyright (c) 2014 All Rights Reserved
// </copyright>
// <summary>
//   The business rule.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace ComparisonTool
{
    using System;

    using ComparisonTool.Annotations;

    /// <summary>
    /// The business rule.
    /// </summary>
    public class BusinessRule
    {
        protected bool Equals(BusinessRule other)
        {
            return string.Equals(this.RuleName, other.RuleName);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            if (ReferenceEquals(this, obj))
            {
                return true;
            }

            if (obj.GetType() != this.GetType())
            {
                return false;
            }

            return Equals((BusinessRule)obj);
        }

        public override int GetHashCode()
        {
            return this.RuleName != null ? this.RuleName.GetHashCode() : 0;
        }

        /// <summary>
        /// The rule Name.
        /// </summary>
        public readonly string RuleName;

        /// <summary>
        /// Initializes a new instance of the <see cref="BusinessRule"/> class.
        /// </summary>
        /// <param name="createdBy">
        /// The created By.
        /// </param>
        /// <param name="guid">
        /// The unique identifier.
        /// </param>
        /// <param name="ruleName">
        /// The rule name.
        /// </param>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="isManaged">
        /// The is managed.
        /// </param>
        public BusinessRule(string createdBy, Guid guid, string ruleName, int state, bool isManaged)
        {
            this.CreatedBy = createdBy;
            this.Guid = guid;
            this.RuleName = ruleName;
            this.State = GetformattedState(state);
            this.IsManaged = isManaged.ToString();
        }

        /// <summary>
        /// Gets or sets state
        /// </summary>
        public string State { get; set; }

        /// <summary>
        /// Gets managed value.
        /// </summary>
        public string IsManaged { get; private set; }

        /// <summary>
        /// Gets or sets the private unique id.
        /// </summary>
        private Guid Guid { [UsedImplicitly] get; set; }

        public string CreatedBy { get; set; }

        /// <summary>
        /// The get formatted state.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private static string GetformattedState(int state)
        {
            switch (state)
            {
                case 0:
                    return "Published";
                default:
                    return "Unpublished";
            }
        }
    }
}
